/*
Implement a stack using pointers.

Program by Thomas Jacob and Syam Kumar
14 February,2001
*/

#include<stdio.h>
#include<conio.h>

int *bottom,*top;

void push()
{
 do
 {
  printf("\nEnter data : ");
  scanf("%d",top++);
  printf("Continue<Y/N>? ");
 }while(toupper(getche())!='N');
}

void pop()
{
 if(top==bottom) {printf("Stack empty."); getch();}  else top--;
}

void view()
{
 int *temp;
 if(top!=bottom)
  {
   temp=top-1;
   while(temp!=bottom-1)
     printf("%d\t",*temp--);
  }
 else printf("Stack empty.");
 getch();
}

void main()
{
 char choice;
 top=bottom;

 do
  {
  clrscr();
  printf("---STACK USING POINTERS ---\n");
  printf("<P>. . . Push\n");
  printf("<D>. . . Pop\n");
  printf("<V>. . . View\n\n");
  printf("<X>. . . Exit\n\nChoice :");
  choice=toupper(getche());
  printf("\n---------------------------\n");
  switch(choice)
   {
    case 'P': push(); break;
    case 'D': pop(); break;
    case 'V': view(); break;
   }
  } while(choice!='X');
}


